/***************************************************************************
begin                : May 01 2011
copyright            : (C) 2011 by Benoit Valot
email                : benvalot@gmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 23 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

package val.lemonde;

import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;

public class ActivityLemondeBase extends FragmentActivity {

	protected SharedDatas datas;

	public SharedDatas get_datas() {
		datas = SharedDatas.shared;
		if (datas == null)
			return (new SharedDatas(this));
		datas.setContext(this);
		return datas;
	}
	
	protected boolean isDualMode(){
		return(this.findViewById(R.id.container_little)!=null);
	}

	public void load_content() {

	}

	protected void erreur_loading(String error) {
		Log.e("lemonde", error);
		FragmentManager fragmentManager = getSupportFragmentManager();
		FragmentTransaction fragmentTransaction = fragmentManager
				.beginTransaction();
		FragmentReload fragment = FragmentReload.newInstance(error);
		fragmentTransaction.replace(R.id.container, fragment);
		fragmentTransaction.commitAllowingStateLoss();
//		AlertDialog.Builder builder = new AlertDialog.Builder(this);
//		builder.setMessage(
//				"Une erreur réseau s'est produite lors du chargement.")
//				.setCancelable(false)
//				.setPositiveButton("Réessayer",
//						new DialogInterface.OnClickListener() {
//							public void onClick(DialogInterface dialog, int id) {
//								ActivityLemondeBase.this.load_content();
//							}
//						})
//				.setNegativeButton("Annuler",
//						new DialogInterface.OnClickListener() {
//							public void onClick(DialogInterface dialog, int id) {
//								ActivityLemondeBase.this.finish();
//							}
//						});
//		AlertDialog quitte = builder.create();
//		quitte.show();
	}
	
	public void selfReload(View view){
		ActivityLemondeBase.this.load_content();
	}

	public boolean onOptionsItemSelected(MenuItem item) {
		// // Handle item selection
		switch (item.getItemId()) {
		case R.id.param_item:
			Log.d("lemonde", "parametres");
			Intent i = new Intent(getApplicationContext(),
					ActivityConfiguration.class);
			this.startActivity(i);
			return true;
		case R.id.back:
			Log.d("lemonde", "back");
			this.onBackPressed();
			return true;
		case R.id.actionbar_item_home:
			Log.d("lemonde", "home");
			i = new Intent(Intent.ACTION_VIEW);
			Uri u = Uri.parse("http://www.lemonde.fr/");
			i.setData(u);
			startActivity(i);
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}
}
